<?php

class Industries extends Eloquent {
    protected $table = 'industries';
	 public static function Show($shop_id){
    	try{

    		$query_view="SELECT * FROM industries WHERE shop_id = $shop_id ";
    		return DB::select(DB::raw($query_view));
    	}
    	catch(Exception $e){

    		throw $e;
    	}
    }
    public static function getIndustryId($name)
    {
        try
        {
            $query_industy_id=self::where('name','=',$name)
                                ->select('id')->first();

            //var_dump($query_shop_id); exit;
            if($query_industy_id)
            {
                return $query_industy_id->id;
            }
            return -1;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    public static function Insert($name,$description,$shop_id){
    	try{
    		//$query_insert ="INSERT INTO industries(created_at, updated_at, name, description,shop_id) VALUES (CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, '$name', '$description', $shop_id)";
//    		$insert = DB::Insert($query_insert);
//            return true;
            
            $industrie = new Industries();    
            $industrie->name= $name;
            $industrie->description= $description;
            $industrie->shop_id= $shop_id;
            $industrie->save();
            $industry_id = $industrie->id;
            return $industry_id;
            

    	}
    	catch(Exception $e)
    	{
    		throw $e;
    	}
    }
    public static function Edit($industry_id,$name,$description){
    	try{ 

    		$query_edit="UPDATE industries 
            SET created_at=CURRENT_TIMESTAMP, updated_at=CURRENT_TIMESTAMP, name='$name', description='$description' WHERE id = $industry_id";
    		
    		 $edit = DB::UPDATE($query_edit);
    		return true;
    	}
    	catch(Exception $e)
    	{
    		throw $e;
    	}
    }

    public static function deletedata($industry_id){
    	try{

    		$query_delete = "DELETE FROM industries WHERE id= $industry_id";
    		 $delete =DB::delete($query_delete);
             return true;
    	}
    	catch(Exception $e)
    	{
    		throw $e;
    	}
        
    }
}
